package 蓝桥._14届.小蓝的旅行计划;

import java.util.Arrays;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt(), m = scan.nextInt();
        int[][] nodes = new int[n][3];
        for (int i = 0; i < n; i++) {
            nodes[i][0] = scan.nextInt();
            nodes[i][1] = scan.nextInt();
            nodes[i][2] = scan.nextInt();
        }
        long[][] dp = new long[n][m+1];
        // 初始化, 一开始邮箱是满的
        for (int i = 0; i < n; i++) {
            Arrays.fill(dp[i],-1);
        }
        for (int i = 0; i <= m; i++) {
            int used = nodes[0][0]; // 消耗的汽油
            int rest = m - used;    // 当前剩余的其余
            if(rest > i)
                continue;
            // 要是的当前油箱剩余为 i, 需买 i - rest
            if(i - rest <= nodes[0][2]){
                dp[0][i] = (long) (i - rest) *nodes[0][1];
            }else
                break;;

        }
        //
        for(int i=1;i<n;i++){
            for (int j = 0; j <= m; j++) {   // 离开i站点时车的剩余油量
                for (int k = 0; k <= m; k++) {   // 离开i-1站点时车的剩余油量
                    if(dp[i-1][k]==-1)
                        continue;

                    int used = nodes[i][0]; // 消耗的汽油
                    int rest = k - used;    // 当前剩余的汽油
                    int need = j - rest;    // 当前需要加的油
                    if(rest<0)
                        continue;
                    if(need > nodes[i][2])
                        continue;
                    if(need < 0)
                        continue;
                    // 要是的当前油箱剩余为 i, 需买 i - rest
                    if(dp[i][j]<0)
                        dp[i][j] = dp[i-1][k] + (long) need * nodes[i][1];
                    else
                        dp[i][j] = Math.min( dp[i][j],dp[i-1][k] + (long) need * nodes[i][1]);
                }
            }
        }

        for (int i = 0; i < m; i++) {
            if(dp[n-1][i]>=0){
                System.out.println(dp[n-1][i]);
                break;
            }
            if(i==m-1)
                System.out.println(-1);
        }

        scan.close();
    }
}